package logic

import (
	"context"
	"renting-demo/cart_srv/cart"

	"renting-demo/api/internal/svc"
	"renting-demo/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type ProductStockLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewProductStockLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ProductStockLogic {
	return &ProductStockLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ProductStockLogic) ProductStock(req *types.ProductStockReq) (resp *types.Data, err error) {
	// todo: add your logic here and delete this line
	res, _ := l.svcCtx.CartServer.Stock(context.Background(), &cart.ProductStockReq{
		GoodsId: int64(req.GoodsId),
		Num:     int64(req.Num),
	})
	if res.Status == "0" {
		return &types.Data{
			Code:    10001,
			Message: "更新库存失败",
		}, nil
	}
	return &types.Data{
		Code:    10001,
		Message: "更新库存成功",
	}, nil
}
